package dk.rhok.findstufffast;



import android.content.*;
import android.location.*;



public class LocationDatabase
{
    Location[] targetLocations;



    public LocationDatabase(Context context)
    {
        String[] mock_locations = context.getResources().getStringArray(R.array.mock_locations);
        targetLocations = new Location[mock_locations.length];
        for(int i = 0; i < mock_locations.length; i++)
        {
            String[] coordStrings = mock_locations[i].split(" ");
            Location l = new Location("mock_locations");
            l.setAccuracy(0.0f);
            l.setLatitude(Double.parseDouble(coordStrings[0]));
            l.setLongitude(Double.parseDouble(coordStrings[1]));
            targetLocations[i] = l;
        }
    }



    public Location getBestLocation(Location phoneLocation)
    {
        double bestDist = Double.POSITIVE_INFINITY;
        Location bestLocation = null;
        for(Location targetLocation : targetLocations)
        {
            double dist = targetLocation.distanceTo(phoneLocation);
            if(dist < bestDist)
            {
                bestDist = dist;
                bestLocation = targetLocation;
            }
        }
        return bestLocation;
    }
}